function draw() {
    ctx.clearRect(0, 0, canvas_width, canvas_height);
    var i, pi, x_dist, y_dist, dist, w;
    random_points.forEach(function (p, index) {
        p.x += p.xa;
        p.y += p.ya;
        p.xa *= p.x > canvas_width || p.x < 0 ? -1 : 1;
        p.ya *= p.y > canvas_height || p.y < 0 ? -1 : 1;
        ctx.fillRect(p.x - 0.5, p.y - 0.5, 4, 4);
        ctx.fillStyle = '#2f2f2f';
        for (i = index + 1; i < random_points.length; i++) {
            pi = random_points[i];
            if (pi.x !== null && pi.y !== null) {
                x_dist = p.x - pi.x;
                y_dist = p.y - pi.y;
                dist = x_dist * x_dist + y_dist * y_dist;
                w = (pi.max - dist) / pi.max + 0.2;
                ctx.beginPath();
                ctx.lineWidth = w;
                ctx.strokeStyle = 'rgba(50,50,50,' + w + ')';
                ctx.moveTo(p.x, p.y);
                ctx.lineTo(pi.x, pi.y);
                ctx.stroke();
            }
        }
    });
    requestAnimationFrame(draw);
}
for (var i = 0; i < 50; i++) {
    var x = Math.random() * canvas_width,
        y = Math.random() * canvas_height,
        xa = .8 * Math.random() - .4,
        ya = .8 * Math.random() - .4,
        max = 10000;
    random_points[i] = {x: x, y: y, xa: xa, ya: ya, max: max};
}
setTimeout(draw, 100);